<?php
/*
  Copyright (c) 2010-02 SongCMS
  SongCMS All Rights Reserved.
  Support:www.SongCMS.com
  QQ:544255858   19951025
  Author:Song  Version:3.17
  Date:2010-08-12 09:28:32
*/

include_once('Admin.php');
include_once('../config/field.php');
$ColumnType = 1; //栏目类型:0栏目内容分类,1新闻分类,2产品分类
if (!is_numeric($_GET['ID'])) {MsgBox (1,'ID参数出现非数字错误！','-1');}
$news_field = $customize_field['news']; //自定义字段
if(!is_array($news_field)) $news_field = array();
$nNews = $db->SelectSQL("SELECT * FROM `{$dbprefix}news` WHERE `ID` = '{$_GET['ID']}'",1);
if(count($nNews)==0){MsgBox (1,'不存在的新闻！','-1');}
$nNews = array_shift($nNews);

if($_POST['Action']=='UpDate'){
	if(trim($_POST['NewsTitle']=='')){MsgBox (1,'操作失败，请填写新闻标题！','-1');}
	if($ConfigNewsClick==1 && !is_numeric($_POST['NewsClick'])){MsgBox (1,'操作失败，点击数必须为数字！','-1');}
	if($ConfigNewsSort==1 && !is_numeric($_POST['NewsSort'])){MsgBox (1,'操作失败，排序必须为数字！','-1');}
	$ConfigNewsExternal == 1 ? $NewsExternal = $_POST['NewsExternal'] : $NewsExternal = 0; //发布形式
	$NewsExternal == 1 ? $NewsContent = $_POST['NewsUrl'] : $NewsContent = $_POST['NewsContent']; //外部链接地址、内容
	if($NewsContent==''){MsgBox (1,'操作失败，新闻链接地址与新闻内容至少填写一项！','-1');}
	$ConfigNewsRecommended == 1 ? $NewsRecommended = $_POST['NewsRecommended'] : $NewsRecommended = 0 ; //新闻推荐
	$ConfigNewsAudit == 1 ? $NewsAudit = $_POST['NewsAudit'] : $NewsAudit = 1; //新闻审核
	$ConfigNewsClick == 1 ? $NewsClick = $_POST['NewsClick'] : $NewsClick = 0; //点击数
	$ConfigNewsSort == 1 ? $NewsSort = $_POST['NewsSort'] : $NewsSort = 0; //排序

	if(!empty($_FILES['NewsPhoto']['tmp_name'])){
		$npics = picstreatment(2,'NewsPhoto');
		$upURL_1 = $upURL1;
	} else {
		$upURL_1 = $nNews['NewsPhoto'];
		$npics = true;
	}
    if(!empty($_FILES['NewsPhoto2']['tmp_name'])){
		picstreatment(2,'NewsPhoto2');
		$upURL_2 = $upURL1;
	} else {
		$upURL_2 = $nNews['NewsPhoto2'];
		$npics = true;
	}
    if(!empty($_FILES['NewsPhoto3']['tmp_name'])){
		picstreatment(2,'NewsPhoto3');
		$upURL_3 = $upURL1;
	} else {
		$upURL_3 = $nNews['NewsPhoto3'];
		$npics = true;
	}
    if(!empty($_FILES['NewsPhoto4']['tmp_name'])){
		picstreatment(2,'NewsPhoto4');
		$upURL_4 = $upURL1;
	} else {
		$upURL_4 = $nNews['NewsPhoto4'];
		$npics = true;
	}
    if(!empty($_FILES['NewsPhoto5']['tmp_name'])){
		picstreatment(2,'NewsPhoto5');
		$upURL_5 = $upURL1;
	} else {
		$upURL_5 = $nNews['NewsPhoto5'];
		$npics = true;
	}

	$sql_add = NULL; //自定义字段
	foreach($news_field as $i => $n){
		$sql_add .= "`{$n[0]}` = '" . trim($_POST[$n[0]]) . "',";
	}

	$SQL = "UPDATE `" . $dbprefix . "news` SET
	`NewsRela` = '" . $_POST['NewsRela'] . "',
	`NewsTitle` = '" . $_POST['NewsTitle'] . "',
	`NewsTitleColor` = '" . $_POST['NewsTitleColor'] . "',
	`NewsExternal` = '" . $NewsExternal . "',
	`NewsContent` = '" . $NewsContent . "',
	`NewsPhoto` = '" . $upURL_1 . "',
	`NewsPhoto2` = '" . $upURL_2 . "',
	`NewsPhoto3` = '" . $upURL_3 . "',
	`NewsPhoto4` = '" . $upURL_4 . "',
	`NewsPhoto5` = '" . $upURL_5 . "',
	`NewsSource` = '" . $_POST['NewsSource'] . "',
	`NewsRecommended` = '" . $NewsRecommended . "',
	`NewsKeyWord` = '" . $_POST['NewsKeyWord'] . "',
	`NewsAudit` = '" . $NewsAudit . "',
	`NewsClick` = '" . $NewsClick . "',{$sql_add}
	`NewsSort` = '" . $NewsSort . "' WHERE `ID` = '" . $_GET['ID'] . "' LIMIT 1 ;";

	unset($ConfigNewsClick,$NewsAudit,$NewsRecommended,$NewsContent,$ConfigNewsRecommended,$ConfigNewsAudit,$ConfigNewsClick,$ConfigNewsSort);
	if($db->ExecuteSQL($SQL)){
		AdminLog(1,$Lang,'修改新闻内容，结果：操作成功！');
		if($npics !== true){
			MsgBox (1,"新闻修改成功，图片上传失败，返回信息：{$npics}","NewsUpDate.php?Lang={$Lang}&ID={$_GET['ID']}");
		}
		if($_POST['isHTML'] == 'yes'){
			$ID = $_GET['ID'];
			MsgBox(0,'',"HtmlComplex.php?Lang={$Lang}&Action=ComplexNews&StartID={$ID}&EndID={$ID}");
		}
		MsgBox (1,'新闻内容修改成功！','NewsManage.php?Lang=' . $Lang);
	} else {
		AdminLog(1,$Lang,'修改新闻内容，结果：操作失败！');
		MsgBox (1,'操作失败，请检查您提交的数据是否正确！','-1');
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="./images/adminstyle.css" rel="stylesheet" type="text/css" />
<link href="../tools/highslide/highslide.css" rel="stylesheet" type="text/css" />
<link rel="Shortcut Icon" href="../favicon.ico">
<link rel="Bookmark" href="../favicon.ico">
<script src="../js/csshovernotie6.js" type="text/javascript"></script>
<script src="../tools/highslide/highslide.js" type="text/javascript"></script>
<script src="../js/jquery.js" type="text/javascript"></script>
<script src="../tools/ckeditor/ckeditor.js" type="text/javascript"></script>
<script language="javascript">
function check(ID){ //隐藏、显示相关元素
	if(ID==2) {
		document.getElementById("NewsContertTr").style.display = "";
		document.getElementById("NewsUrlTr").style.display = "none";
	} else if(ID==3) {
		document.getElementById("NewsContertTr").style.display = "none";
		document.getElementById("NewsUrlTr").style.display = "";
	}
}

function Check() {
	if (document.form1.NewsRela.value==""){
		alert("请选择新闻所属类别！");
		document.form1.NewsRela.focus();
		return false;
	}
	if (document.form1.NewsTitle.value==""){
		alert("请填写新闻标题！");
		document.form1.NewsTitle.focus();
		return false;
	}
}

//标题文件颜色选择
var tempColor;
function returnColor(){
	var Hcolor = dlgHelper.ChooseColorDlg(tempColor).toString(16);
	with(event.srcElement){tempColor = ((Hcolor.length<6)?"000000".substring(0,6-Hcolor.length):"") + Hcolor;}
	document.getElementById('SelectColor').style.backgroundColor = '#' + tempColor;
	document.getElementById('NewsTitleColor').value = '#' + tempColor;
	document.getElementById('NewsTitle').style.color= '#' + tempColor;
}
function DelColor(){
	document.getElementById('SelectColor').style.backgroundColor = '#CCCCCC';
	document.getElementById('NewsTitleColor').value = '';
	document.getElementById('NewsTitle').style.color= '#000000';
}
hs.graphicsDir = '../tools/highslide/graphics/';
hs.showCredits = false;
hs.outlineType = 'rounded-white';
hs.restoreTitle = '关闭';
$(document).ready(function(){CKEDITOR.replace('NewsContent');});
</script>
</head>
<body>
<br />
<OBJECT id="dlgHelper" CLASSID="clsid:3050f819-98b5-11cf-bb82-00aa00bdce0b" width="0px" height="0px"></OBJECT> <!--Win拾色器-->
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr class="Notodd">
	<td>&nbsp;</td>
	<td align="right">
		<input type="button" value="添加新闻" onClick="javascript:location.href='NewsAdd.php?Lang=<?php echo $Lang?>'">
		<input type="button" value="新闻管理" onClick="javascript:location.href='NewsManage.php?Lang=<?php echo $Lang?>'">
		<input type="button" value="类别管理" onClick="javascript:location.href='NewsColumnManage.php?Lang=<?php echo $Lang?>'">
	</td>
	</tr>
</table>
<table width="98%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC">
<form id="form1" name="form1" method="post" action="NewsUpDate.php?Lang=<?php echo $Lang?>&ID=<?php echo $_GET['ID']?>" enctype="multipart/form-data" onSubmit="return Check()">
  <tr class="odd">
    <td colspan="3" align="center" class="Main_Title">修改新闻<?php echo $OnWebLangName?></td>
  </tr>
  <tr class="odd">
    <td width="100" align="right">选择栏目：</td>
<td>
<select name="NewsRela" id="NewsRela">
<option selected="selected" value="">==请选择栏目==</option>
<?php
$Rs = $db->SelectSQL("SELECT `ID`,`ColumnRela`,`ColumnName`,`ColumnLevel`,`ColumnTime`,`ColumnSort` FROM `" . $dbprefix . "column` WHERE ColumnType = $ColumnType && ColumnLang = $Lang;",2);
@$Rs = sdb::column_sort($Rs);
for ($i=0;$i<count($Rs);$i++ ) {
	Html($Rs[$i]);
	for ($x=1;$x<$Rs[$i][3];$x++){$Spaces .= '├┈┈';} //加与栏目级数相同的空格
	$Rs[$i][3] > 1 ? $Spaces = $Spaces . $Rs[$i][2] : $Spaces = $Rs[$i][2]; //一级栏目前不加空格符
	if($Rs[$i][1] != $nNews['NewsRela']){
		echo '<option value="' . $Rs[$i][1] . '">' . $Spaces . '</option>' . "\n";
	}else{
		echo '<option selected="selected" value="' . $Rs[$i][1] . '">' . $Spaces . '</option>' . "\n";
	}
	unset($Spaces);
}
unset($Rs,$i,$x);
?>
</select>
<span class="red">*</span></td>
    <td><a href="NewsColumnManage.php?Lang=<?php echo $Lang?>"><font color="#0000FF">点击添加新闻类别</font></a></td>
  </tr>
  <tr class="odd">
    <td align="right">新闻标题：</td>
    <td><input name="NewsTitle" type="text" class="input2" id="NewsTitle" value="<?php echo Html($nNews['NewsTitle'])?>" style="color:<?php echo $nNews['NewsTitleColor']?>" maxlength="100" />
<?php
if($ConfigNewsTitleColor == 1){
	if(stripos($_SERVER["HTTP_USER_AGENT"],'MSIE')){ //检测客户端是否为IE浏览器
		echo '<input id="SelectColor" title="选择字体颜色" style="height:13px; width:13px; background-color:' . $nNews['NewsTitleColor'] . ';" readonly="readonly" onClick="returnColor()">' . "\n";
		$DelColor = '<a href="javascript:" title="点击清除颜色" onClick="DelColor()"><img src="../images/check_error.gif" width="13" height="13" border="0" /></a>';
	} else {
		echo '<Select Name="SelectColor" id="SelectColor" OnChange="NewsTitle.style.color=this.value; NewsTitleColor.value=this.value; this.style.backgroundColor=this.value;">
		<Option value="" selected="selected">选择字体颜色</Option>';
		include_once('../config/colorarray.php');
		foreach ($ColorArray as $key => $value){
			echo '<option value="' . $value . '" style="background:' . $value . '"></option>' . "\n";
		}
		echo '</Select>';
		unset($ColorArray,$key,$value);
	}
	echo ' <Input Name="NewsTitleColor" type="text" id="NewsTitleColor" value="' . $nNews['NewsTitleColor'] . '" size="8" readonly="true" style="color:#999999;" /> ' . "\n";
	echo $DelColor;
}

?>
</td>
    <td><?php if($ConfigNewsTitleColor == 1) echo '可选择前台显示的标题字体颜色';?></td>
  </tr>
<?php if($ConfigNewsExternal == 1){ ?>
  <tr class="odd">
    <td align="right">发布形式：</td>
    <td><input name="NewsExternal" type="radio" id="radio" value="0" <?php if($nNews['NewsExternal']==0){echo 'checked="checked"';}?> onClick="return check(2)" />
      内部新闻
      <input type="radio" name="NewsExternal" id="radio2" value="1" <?php if($nNews['NewsExternal']==1){echo 'checked="checked"';}?> onClick="return check(3)" />
      外部新闻</td>
    <td>外部新闻将直接链接到指定的外部站点</td>
  </tr>
  <tr id="NewsUrlTr" <?php if($nNews['NewsExternal']==0){echo 'style="display:none;"';}?> class="odd">
    <td align="right">链接地址：</td>
    <td><input name="NewsUrl" type="text" class="input2" id="NewsUrl" value="<?php if($nNews['NewsExternal']==1){echo Html($nNews['NewsContent']);}?>" maxlength="255" />
      <span class="red">*</span></td>
    <td>该项只对外部新闻有用,如 <font color="#008000">http://www.SongCMS.com</font></td>
  </tr>
<?php } if($ConfigNewsPhoto == 1){?>
  <tr class="odd">
    <td align="right">新闻图片：</td>
    <td><input name="NewsPhoto" type="file" id="NewsPhoto" size="35" /></td>
    <td><?php if(!empty($nNews['NewsPhoto'])) echo '<a href="../' . $nNews['NewsPhoto'] . '" onclick="return hs.expand(this);">图片已存在(查看)</a>,不更换图片时不用上传,上传将会替换当前图片；';?></td>
  </tr>
  <tr class="odd">
    <td align="right">新闻图片：</td>
    <td><input name="NewsPhoto2" type="file" id="NewsPhoto2" size="35" /></td>
    <td><?php if(!empty($nNews['NewsPhoto2'])) echo '<a href="../' . $nNews['NewsPhoto2'] . '" onclick="return hs.expand(this);">图片已存在(查看)</a>,不更换图片时不用上传,上传将会替换当前图片；';?></td>
  </tr>
  <tr class="odd">
    <td align="right">新闻图片：</td>
    <td><input name="NewsPhoto3" type="file" id="NewsPhoto3" size="35" /></td>
    <td><?php if(!empty($nNews['NewsPhoto3'])) echo '<a href="../' . $nNews['NewsPhoto3'] . '" onclick="return hs.expand(this);">图片已存在(查看)</a>,不更换图片时不用上传,上传将会替换当前图片；';?></td>
  </tr>
  <tr class="odd">
    <td align="right">新闻图片：</td>
    <td><input name="NewsPhoto4" type="file" id="NewsPhoto4" size="35" /></td>
    <td><?php if(!empty($nNews['NewsPhoto4'])) echo '<a href="../' . $nNews['NewsPhoto4'] . '" onclick="return hs.expand(this);">图片已存在(查看)</a>,不更换图片时不用上传,上传将会替换当前图片；';?></td>
  </tr>
  <tr class="odd">
    <td align="right">新闻图片：</td>
    <td><input name="NewsPhoto5" type="file" id="NewsPhoto5" size="35" /></td>
    <td><?php if(!empty($nNews['NewsPhoto5'])) echo '<a href="../' . $nNews['NewsPhoto5'] . '" onclick="return hs.expand(this);">图片已存在(查看)</a>,不更换图片时不用上传,上传将会替换当前图片；';?></td>
  </tr>
<?php } if($ConfigNewsSource == 1){?>
  <tr class="odd">
    <td align="right">新闻来源：</td>
    <td><input name="NewsSource" type="text" class="input2" id="NewsSource" value="<?php echo Html($nNews['NewsSource'])?>" maxlength="50" /></td>
    <td>&nbsp;</td>
  </tr>
<?php } if($ConfigNewsKeyWord == 1){?>
  <tr class="odd">
    <td align="right">关 键 字：</td>
    <td><input name="NewsKeyWord" type="text" class="input2" id="NewsKeyWord" value="<?php echo Html($nNews['NewsKeyWord'])?>" /></td>
    <td>将被用来作为SEO优化关键词及Tag关键词，<br />留空时将采用"网站基本设置"中的搜索关键字作为SEO关键词</td>
  </tr>
<?php }

//自定义字段
foreach ($news_field as $i => $n){
	if($n[2] == 'TEXT' || $n[2] == 'MEDIUMTEXT' || $n[2] == 'LONGTEXT'){
		$input = "<textarea name=\"{$n[0]}\" style=\"width:300px; height:120px;\">" . Html($nNews[$n[0]]) . "</textarea>";
	} else {
		$input = "<input name=\"{$n[0]}\" type=\"text\" class=\"input2\" maxlength=\"50\" value=\"" . Html($nNews[$n[0]]) . "\" />";
	}
	echo "<tr class=\"odd\">
    <td align=\"right\">{$n[1]}：</td>
    <td>{$input}</td>
    <td>自定义字段（类型：{$n[2]}）</td>
	</tr>";
}
//End

?>

  <tr id="NewsContertTr" class="odd" <?php if($nNews['NewsContent']==1){echo 'style="display:none;"';}?>>
    <td align="right">新闻内容：</td>
    <td colspan="2"><textarea id="NewsContent" name="NewsContent" rows="10" cols="80"><?php echo htmlspecialchars($nNews['NewsContent']);?></textarea></td>
</tr>
<?php if($ConfigNewsAudit == 1){?>
  <tr class="odd">
    <td align="right">通过审核：</td>
    <td><input name="NewsAudit" type="radio" id="radio3" value="1" <?php if($nNews['NewsAudit']==1) echo 'checked="checked"';?> />
      是
      <input type="radio" name="NewsAudit" id="radio4" value="0" <?php if($nNews['NewsAudit']==0) echo 'checked="checked"';?> />
      否</td>
    <td>未通过审核的新闻将不在任何页面中显示</td>
  </tr>
<?php } if($ConfigNewsRecommended == 1){?>
  <tr class="odd">
    <td align="right">推荐新闻：</td>
    <td><input name="NewsRecommended" type="radio" id="radio5" value="1" <?php if($nNews['NewsRecommended']==1){echo 'checked="checked"';}?> />
      是
      <input name="NewsRecommended" type="radio" id="radio6" value="0" <?php if($nNews['NewsRecommended']==0){echo 'checked="checked"';}?> />
      否</td>
    <td>&nbsp;</td>
  </tr>
<?php } if($ConfigNewsClick == 1){?>
  <tr class="odd">
    <td align="right">点击次数：</td>
    <td><input name="NewsClick" type="text" id="NewsClick" value="<?php echo $nNews['NewsClick']?>" size="6" maxlength="6" />
      <span class="red">*</span></td>
    <td>不建议修改</td>
  </tr>
<?php } if($ConfigNewsSort == 1){?>
  <tr class="odd">
    <td align="right">排　　序：</td>
    <td><input name="NewsSort" type="text" id="NewsSort" value="<?php echo $nNews['NewsSort']?>" size="6" maxlength="6" />
      <span class="red">*</span></td>
    <td>值越大越靠前(不指定将按最新发表排序)</td>
  </tr>
<?php } if($ConfigNewsPublished == 1){?>
  <tr class="odd">
    <td align="right">发 表 人：</td>
    <td><input name="NewsPublished" type="text" disabled="disabled" class="input2" id="NewsPublished" value="<?php echo $nNews['NewsPublished']?>" maxlength="20" readonly="readonly" /></td>
    <td>&nbsp;</td>
  </tr>
<?php } if($ConfigNewsTime == 1){?>
  <tr class="odd">
    <td align="right">发表时间：</td>
    <td><input name="NewsTime" type="text" disabled="disabled" id="NewsTime" value="<?php echo $nNews['NewsTime']?>" readonly="true" /></td>
    <td>&nbsp;</td>
  </tr>
<?php } if($WebStaticHTML == 1){?>
  <tr class="odd">
  	<td align="right">生成静态：</td>
  	<td><input name="isHTML" type="checkbox" id="isHTML" value="yes" />生成HTML</td>
  	<td>添加后将同时生成与该新闻相关的所有静态页面</td>
  	</tr>
<?php }?>
  <tr class="odd">
    <td align="right"><input name="Action" type="hidden" id="Action" value="UpDate" /></td>
    <td><input type="submit" name="button" id="button" value="提 交" class="submit" />
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input type="reset" name="button2" id="button2" value="重 置" class="submit" />
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input type="button" value="返 回" class="submit" name="xback" onclick="history.back(-1)"></td>
    <td>&nbsp;</td>
  </tr>
  </form>
  </table>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="6">
	<tr class="Notodd">
		<td style="color:#333333; line-height:20px;">
		<?php if($ConfigNewsExternal == 1){?>注：1、外部新闻直接链接到其它外部站点，无需添加新闻内容；<?php }?>
		</td>
	</tr>
</table>
<?php unset($nNews);  ?>
</body>
</html>